package br.com.fogas.medicao.menu;

import java.util.List;

import br.com.fogas.medicao.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuAdapter extends BaseAdapter {
	
	private LayoutInflater inflater;
	
	private List<MenuDto> navDrawerItems;
	
	public MenuAdapter(Context context, List<MenuDto> navDrawerItems){
		this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
		this.navDrawerItems = navDrawerItems;
	}

	@Override
	public int getCount() {
		return navDrawerItems.size();
	}

	@Override
	public Object getItem(int position) {		
		return navDrawerItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHolder holder = null;
		
		if (convertView == null) {
                convertView = inflater.inflate(R.layout.menu_list_items, null);
				
                holder = new ViewHolder();
                holder.imgMenuItemsIcon = (ImageView) convertView.findViewById(R.id.imgMenuItemsIcon);
                holder.tvMenuItemsLabel = (TextView) convertView.findViewById(R.id.tvMenuItemsLabel);
                
                convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		MenuDto menuDrawerDTO = (MenuDto) getItem(position);
		holder.imgMenuItemsIcon.setImageResource(menuDrawerDTO.getItem().getImg());
		holder.tvMenuItemsLabel.setText(menuDrawerDTO.getItem().getTitle());
		
		return convertView;
	}
	
	private static class ViewHolder {
		private ImageView imgMenuItemsIcon;
		private TextView tvMenuItemsLabel;
	}
}